【云贝餐饮连锁V2独立版开源】适合奶茶餐饮,快餐,外卖搭建
【源码结构】
生成随机字符串 - 最长为32位字符串
*****************************************************/
function wxNonceStr($length = 16, $type = FALSE,$chars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") {
$str = "";
for ($i = 0; $i < $length; $i ) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
if($type == TRUE){
return strtoupper(md5(time() . $str));
}
else {
return $str;
}
}
/**
* 将xml转为array
* @param string $xml
* @throws WxPayException
*/
function FromXml($xml){
// if(!$xml){
// throw new Exception("xml数据异常!");
// }
//将XML转为array
//禁止引用外部xml实体
libxml_disable_entity_loader(true);
$arr = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
return $arr;
}
//遍历文件夹的文件
/**
* PHP高效遍历文件夹(大量文件不会卡死)
* @param string $path 目录路径
* @param integer $level 目录深度
*/
function list_file($dir) {
$files = [];
if(@$handle = opendir($dir)) {
while(($file = readdir($handle)) !== false) {
if($file != ".." && $file != ".") {
if(is_dir($dir . "/" . $file)) { //如果是子文件夹,进行递归
$files[$file] = list_file($dir . "/" . $file);
} else {
$files[] = $file;
}
}
}
closedir($handle);
}
return $files;
}
//对象转数组
function object_array($array) {
if(is_object($array)) {
$array = (array)$array;
}
if(is_array($array)) {
foreach($array as $key=>$value) {
$array[$key] = object_array($value);
}
}
return $array;
}
//短信验证码生成规则
function generate_code($length = 6) {
$min = pow(10 , ($length - 1));
$max = pow(10, $length) - 1;
return rand($min, $max);
}
//curl远程下载压缩包
function getFile($url, $save_dir = '', $filename = '', $type = 0) {
if (trim($url) == '') {
return false;
}
if (trim($save_dir) == '') {
$save_dir = './';
}
if (0 !== strrpos($save_dir, '/')) {
$save_dir.= '/';
}
//创建保存目录
if (!file_exists($save_dir) && !mkdir($save_dir, 0777, true)) {
return false;
}
//获取远程文件所采用的方法
if ($type) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$content = curl_exec($ch);
curl_close($ch);
} else {
ob_start();
readfile($url);
$content = ob_get_contents();
ob_end_clean();
}
$size = strlen($content);
//文件大小
$fp2 = @fopen($save_dir . $filename, 'a');
fwrite($fp2, $content);
fclose($fp2);
unset($content, $url);
return array(
'file_name' => $filename,
'save_path' => $save_dir . $filename
);
}
// 生成纯字母字符串函数
function rand_string($length) {
$randstr = "";
for ($i = 0; $i < (int) $length; $i ) {
$randnum = mt_rand(0, 51);
if ($randnum < 26) {
$randstr .= chr($randnum 65); // A-Z之间字符
} else {
$randstr .= chr($randnum 71); // a-z之间字符
}
}
return $randstr;
}
//获取访客ip
function getIps(){
if (isset($_SERVER)) {
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
foreach ($arr as $ip) {
$ip = trim($ip);
if ($ip != 'unknown') {
$realip = $ip;
break;
}
}
} else if (isset($_SERVER['HTTP_CLIENT_IP'])) {
$realip = $_SERVER['HTTP_CLIENT_IP'];
} else if (isset($_SERVER['REMOTE_ADDR'])) {
$realip = $_SERVER['REMOTE_ADDR'];
} else {
$realip = '0.0.0.0';
}
} else if (getenv('HTTP_X_FORWARDED_FOR')) {
$realip = getenv('HTTP_X_FORWARDED_FOR');
} else if (getenv('HTTP_CLIENT_IP')) {
$realip = getenv('HTTP_CLIENT_IP');
} else {
$realip = getenv('REMOTE_ADDR');
}
preg_match('/[\\d\\.]{7,15}/', $realip, $onlineip);
$realip = (!empty($onlineip[0]) ? $onlineip[0] : '0.0.0.0');
return $realip;
}
function randoms($length){
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < $length; $i ) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
function axios_request(){
if(Yii::$app->request->isPost){
$postData = file_get_contents('php://input');
$requests = !empty($postData) ? json_decode($postData, true) : array();
$requests=$requests?$requests:$_POST;
return $requests;
}else{
return Yii::$app->request->get();
}
}
//设置session
function setSession($key,$value){
Yii::$app->session->set($key,$value);
}
//获取session
function getSession($key){
$data=Yii::$app->session->get($key);
return $data;
}
//$pathname保存的路径 $filename提交的图片文件参数名
function uploadImage($filename,$pathname=null){
$pathname=$pathname?:date('Y') . "/" . date('m') . "/" . date('d');
$returnPath = '';
$path = 'web/static/'.$pathname;
if (!file_exists($path)) {
mkdir($path, 0777,true);
chmod($path, 0777);
}
$name=date("YmdHis") .rand(1111,9999). '.png';
//$patch = '../'.$path . '/' . $name;
$patch = $path . '/' . $name;
$tmp = UploadedFile::getInstanceByName($filename);
if ($tmp) {
$tmp->saveAs($patch);
$returnPath .= $path . '/' . $name;
}
return Yii::$app->request->hostInfo.'/'.$returnPath;
}
function recurDir($pathName)
{
//将结果保存在result变量中
$result = array();
$temp = array();
//判断传入的变量是否是目录
if(!is_dir($pathName) || !is_readable($pathName)) {
return null;
}
//取出目录中的文件和子目录名,使用scandir函数
$allFiles = scandir($pathName);
//遍历他们
foreach($allFiles as $fileName) {
//判断是否是.和..因为这两个东西神马也不是。。。
if(in_array($fileName, array('.', '..'))) {
continue;
}
//路径加文件名
$fullName = $pathName.'/'.$fileName;
//如果是目录的话就继续遍历这个目录
if(is_dir($fullName)) {
//将这个目录中的文件信息存入到数组中
$result[$fullName] = recurDir($fullName);
}else {
//如果是文件就先存入临时变量
$temp[] = $fullName;
}
}
//取出文件
if($temp) {
foreach($temp as $f) {
$result[] = $f;
}
}
return $result;
}
function checkPassWord($salt,$authkeys,$password){
$new_password = sha1("{$password}-{$salt}-{$authkeys}");
return $new_password;
}
function httpRequest($url, $data = null,$header=null) {
//echo 111;die;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data)) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
if($header) {
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
}
curl_setopt($curl, CURLOPT_HEADER, 0);//返回response头部信息
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//执行
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
function get_server_ip(){
if(isset($_SERVER)){
if($_SERVER['SERVER_ADDR']){
$server_ip=$_SERVER['SERVER_ADDR'];
}else{
$server_ip=$_SERVER['LOCAL_ADDR'];
}
}else{
$server_ip = getenv('SERVER_ADDR');
}
return $server_ip;
}
function getVersion(){
$url=Yii::$app->params['domain_url'].'/admin/install/getdomainlist';
$data['domian_url']=Yii::$app->request->hostInfo;
$result=httpRequest($url,$data);
return json_decode($result,true);
}
function getFileArr($dir){
$file_data=list_file($dir);
$file_arr=[];
foreach ($file_data as $k=>$v){
if(is_array($v)){
foreach ($v as $ko=>$vo){
if(is_array($vo)){
foreach ($vo as $va){
$file_arr[]=$dir.'/'.$k.'/'.$ko.'/'.$va;
}
}else{
$file_arr[]=$dir.'/'.$k.'/'.$vo;
}
}
}
}
return $file_arr;
}
function getZipArr($filePath){
$zip = zip_open($filePath);
$zip_arr=[];
if ($zip){
while($zip_entry = zip_read($zip)){
$name = zip_entry_name($zip_entry);
$zip_arr[]=$name;
}
}
评论